package com.itjavas.cslp2.mapper;

import com.itjavas.cslp2.pojo.entity.Course;
import com.itjavas.cslp2.pojo.entity.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;
@Mapper
@Repository
public interface CourseMapper {
    //创建课程
    @Insert("insert into courses(cover_image,name,description,course_type,price,video_url,material_url,discount,is_featured)" +
            "values (#{cover_image},#{name},#{description},#{course_type},#{price},#{video_url},#{material_url},#{discount},#{is_featured})")
    Boolean createCourse(Course course);

    //查询所有课程
    @Select("select * from courses")
    List<Course> findAllCourse();

    //编辑已有课程
    @Update("UPDATE courses SET cover_image = #{cover_image}, name=#{name}, " +
            "description = #{description},course_type = #{course_type}, " +
            "price = #{price}, video_url = #{video_url}, material_url = #{material_url}, " +
            "discount = #{discount}, is_featured = #{is_featured}, WHERE id = #{userid}")
    Boolean editCourse(Course course);

    //删除课程
    @Delete("delete from courses where id=#{courseId}")
    Boolean delete(String courseId);

    //审核资料
    @Update("update material set is_exam=#{isExam} where id=#{id}")
    Boolean examMaterial(Course course);
}
